package com.skyable.account.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.skyable.account.entity.SysUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * @author GaoYuan
 * @date 2020/10/23 9:42
 * @desc
 */
@Mapper
public interface UserMapper extends BaseMapper<SysUser> {

    /**
     * 创建用户表
     * @param tableName
     * @return
     */
    @Update({"<script>" +
            "CREATE TABLE ${tableName} (" +
            "uid bigint(20) NOT NULL AUTO_INCREMENT,",
            "password varchar(64) NOT NULL DEFAULT '',",
            "email varchar(64) DEFAULT '',",
            "phone char(16) DEFAULT '' COMMENT '手机号',",
            "open_id char(64) DEFAULT '' COMMENT 'openId',",
            "nick_name varchar(32) DEFAULT '' COMMENT '别名',",
            "status int(8) NOT NULL DEFAULT '1',",
            "token varchar(32) NOT NULL,",
            "token_expire varchar(32) NOT NULL,",
            "refresh_token varchar(32) NOT NULL,",
            "refresh_token_expire varchar(32) NOT NULL,",
            "img_url varchar(255) DEFAULT NULL,",
            "create_time datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',",
            "modify_time datetime DEFAULT CURRENT_TIMESTAMP COMMENT '最后修改时间',",
            "PRIMARY KEY (uid,open_id),",
            "KEY email (email) USING HASH,",
            "KEY phone (phone) USING HASH,",
            "KEY nick_name (nick_name) USING HASH",
            ") ENGINE=InnoDB DEFAULT CHARSET=utf8;",
            "</script>"
    })
    int createTable(@Param("tableName") String tableName);

    /**
     * 删除用户表
     * @param tableName
     * @return
     */
    @Update({"<script>" +
            "drop table ${tableName}",
            "</script>"
    })
    int dropTable(@Param("tableName") String tableName);

}
